﻿@using Masa.Blazor.Presets

<div class="text-center">
    <MSelect @bind-Value="_precision"
             Label="Precision"
             Items="@Items"
             ItemText="i => i.ToString()"
             ItemValue="i => i"
             Class="d-inline-block"
             Style="max-width: 180px">
    </MSelect>

    <PMobileTimePicker @bind-Value="_time" Precision="_precision" @key="_precision">
        <ActivatorContent>
            <MButton Color="primary" Class="text-capitalize" Text @attributes="@context.Attrs">
                @(ComputedTime.ToString("HH:mm:ss"))
            </MButton>
        </ActivatorContent>
    </PMobileTimePicker>
</div>

@code {

    private TimeOnly _time;
    private TimePrecision _precision = TimePrecision.Second;

    private readonly static List<TimePrecision> Items = new()
    {
        TimePrecision.Hour,
        TimePrecision.Minute,
        TimePrecision.Second
    };

    private TimeOnly ComputedTime => _precision switch{
        TimePrecision.Hour => new TimeOnly(_time.Hour, 0, 0),
        TimePrecision.Minute => new TimeOnly(_time.Hour, _time.Minute, 0),
        _ => _time
    };

}
